package com.slz3.business.module.memberManagement.memThirdLoginInfo.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.memberManagement.memThirdLoginInfo.domain.MemThirdLoginInfo;
import com.slz3.business.module.memberManagement.memThirdLoginInfo.domain.MemThirdLoginInfoFactory;
import com.slz3.business.module.memberManagement.memThirdLoginInfo.steward.MemThirdLoginInfoSpecification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.util.*;

@Slf4j
@Service
public class MemThirdLoginInfoServiceImpl implements MemThirdLoginInfoService {

    @Override
    public MemThirdLoginInfo save(MemThirdLoginInfo memThirdLoginInfo) {
        return Repositorys.memThirdLoginInfo.save(MemThirdLoginInfoFactory.initBaseFields(memThirdLoginInfo));
    }

    @Override
    public Page<MemThirdLoginInfo> page(MultiValueMap<String, String> params) {
        Page<MemThirdLoginInfo> memThirdLoginInfoPage = Repositorys.memThirdLoginInfo.findAll(
                MemThirdLoginInfoSpecification.findJoin(params), PageableSteward.extract(params)
        );
        return memThirdLoginInfoPage;
    }

    @Override
    public MemThirdLoginInfo modify(MemThirdLoginInfo memThirdLoginInfoNew) {
        return Repositorys.memThirdLoginInfo.saveAndFlush(MemThirdLoginInfoFactory.initBaseFields(memThirdLoginInfoNew));
    }

    @Override
    public Optional<MemThirdLoginInfo> single(UUID uuid) {
        return Repositorys.memThirdLoginInfo.findById(uuid);
    }

    @Override
    public List<MemThirdLoginInfo> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.memThirdLoginInfo.findAllById(uuids);
    }

    @Override
    public List<MemThirdLoginInfo> delete(List<MemThirdLoginInfo> memThirdLoginInfoList) {
        memThirdLoginInfoList.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            MemThirdLoginInfoFactory.initBaseFields(item);
        });
        return Services.memThirdLoginInfoTransactional.batchModify(memThirdLoginInfoList);
    }

}
